package pzl.com.transitionsframework;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;

import pzl.com.transitionsframework.transition.CustomTransition1;

public class Activity3 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_3);

        executeTransition();
    }

    public void executeTransition() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            postponeEnterTransition();
        }

        final View decorView = getWindow().getDecorView();
        getWindow().getDecorView().getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                decorView.getViewTreeObserver().removeOnPreDrawListener(this);
                supportStartPostponedEnterTransition();
                return true;
            }
        });

        CustomTransition1 transition = new CustomTransition1();

        transition.setDurationCivPosition(4000);
        transition.setDurationCivSize(4000);
        transition.setmCivPositionInterpolator(new LinearInterpolator());
        transition.setmCivSizeInterpolator(new LinearInterpolator());

        transition.setDurationItem(2000);
        transition.setmItemInterpolator(new AccelerateInterpolator());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //transition.addTarget("civ");
            transition.addTarget("container");
            getWindow().setSharedElementEnterTransition(transition);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();//怎么协调transition正确反着播放
    }

}
